import java.util.Arrays;

public class Test {

    //冒泡排序（升序）
    public static void bubbleSort(int[] arr){
        for (int i = 0; i < arr.length - 1; i++) {
            boolean flag = false;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if(arr[j] > arr[j+1]){
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                    flag = true;
                }
            }
            if(flag == false){
                break;
            }
        }
    }

    public static void main2(String[] args) {
        int[] arr = {4,5,8,6,1,0};
        bubbleSort(arr);
        System.out.println(Arrays.toString((arr)));
    }
    public static int find(int[] arr, int key){
        int left = 0;
        int right = arr.length - 1;
        while(left < right){
            int mid = (left + right) / 2;
            if(arr[mid] == key){
                return mid;
            }else if(arr[mid] > key){
                left = mid + 1;
            }else{
                right = mid - 1;
            }
        }
        return -1;
    }
    //二分查找
    public static void main1(String[] args) {
        int[] arr = {5,8,4,6,10,12};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        int ret = find(arr,6);
        System.out.println(ret);
    }
}
